package com.alex.service.Search_Plans;

import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.WildcardQuery;

import static com.alex.utils.MyUtils.zsout;


/**
 * @Author: 张福垒
 * @Date: 2024/11/27 16:32
 * @Description:
 * @phone: 13864677931
 */
public class Ts_Wildcard_query {
    /**
     * 针对主题的 不分词的检索方法 根据输入的单次或者汉字长度来判断需要命中X/Y 或者 X% 之多少的数字
     *
     * @param freeWord
     * @return
     */
    public static Query ts_wildcard_query(String freeWord, boolean printLog) {
        zsout("[TS][模糊][" + freeWord + "]", printLog);

        BoolQuery.Builder builder = new BoolQuery.Builder();

        builder.should(WildcardQuery.of(i -> i.field("enti.wildcard").value(freeWord.toLowerCase()))._toQuery());
        builder.should(WildcardQuery.of(i -> i.field("cnti.wildcard").value(freeWord.toLowerCase()))._toQuery());
        builder.should(WildcardQuery.of(i -> i.field("enab.wildcard").value(freeWord.toLowerCase()))._toQuery());
        builder.should(WildcardQuery.of(i -> i.field("cnab.wildcard").value(freeWord.toLowerCase()))._toQuery());
        builder.should(WildcardQuery.of(i -> i.field("enkw.wildcard").value(freeWord.toLowerCase()))._toQuery());
        builder.should(WildcardQuery.of(i -> i.field("cnkw.wildcard").value(freeWord.toLowerCase()))._toQuery());


        return builder.build()._toQuery();

    }

}
